package com.wslNB.thymeleaf.controller;

import com.wslNB.thymeleaf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {


    /**
     * 访问/thymeleaf/hello  跳转到demo页面
     *
     * @param model
     * @return
     */
    @RequestMapping("/hello")
    public String hello(Model model) {

        model.addAttribute("hello", "hello Word");
        return "demo";
    }

    @RequestMapping("/heihei")
    public String heihei(Model model, String id) {

        model.addAttribute("hello", "hello Word2222");
        System.out.println("接收id：" + id);

        //list
        List<User> users = new ArrayList<>();
        users.add(new User(1, "张三", "深圳"));
        users.add(new User(1, "李四", "北京"));
        users.add(new User(1, "王五", "武汉"));
        model.addAttribute("users", users);

        //Map定义
        Map<String, Object> map = new HashMap<>();
        map.put("No","123");
        map.put("address","深圳");
        model.addAttribute("map",map);

        //存储一个数组
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);


        //日期
        model.addAttribute("date",new Date());

        //if条件
        model.addAttribute("age",22);

        return "demo";
    }


}
